package com.tinyseed.emcp.api.productionRule.bean;

import com.tinyseed.emcp.api.basicdata.domain.convert.DTOConvert;
import com.tinyseed.emcp.api.productionRule.entity.Distribution;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @Description
 * @Author Henry
 * @Date 2019-12-18
 */

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class DistributionInputDTO implements Serializable {

    /**
     * 唯一主键
     */
    @Id
    @GeneratedValue()
    private Long id;

    /**
     * 企业id
     */
    private Long enterpriseId;

    /**
     * 车间id
     */
    private Long workshopId;

    /**
     * 监测点id
     */
    private Long monitorId;

    /**
     * 减排方案id
     */
    private Long producesetId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 最后修改时间
     */
    private Date modifyTime;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 最后操作人
     */
    private String modifier;

    /**
     * 监控点集合
     */
    private String monitorIds;

    public Distribution convertToDistribution() {
        DistributionInputDTO.DistributionInputDTOConvert convert = new DistributionInputDTO.DistributionInputDTOConvert();
        Distribution result = convert.convert(this);
        return result;
    }

    private static class DistributionInputDTOConvert implements DTOConvert<DistributionInputDTO, Distribution> {

        @Override
        public Distribution convert(DistributionInputDTO distributionInputDTO) {
            Distribution distribution = new Distribution();
            BeanUtils.copyProperties(distributionInputDTO, distribution);
            Timestamp nowTime = new Timestamp(new Date().getTime());
            distribution.setModifyTime(nowTime);
            return distribution;
        }
    }
}
